from django.db import models
from main.common.perm.perms_config import ALL_PERMS


class JwtLog(models.Model):
    """jwt token申请记录，用于记录用户登录日志"""
    user = models.ForeignKey(
        'auth.User',
        on_delete=models.SET_NULL,
        default=None,
        null=True,
    )
    exp = models.DateTimeField(
        '过期时间',
        help_text='过期时间',
    )
    ip_addr = models.CharField(
        'ip_addr',
        max_length=20,
        default='',
    )

    create_time = models.DateTimeField(
        '添加时间',
        help_text='添加时间',
        auto_now_add=True
    )
    update_time = models.DateTimeField(
        '更新时间',
        help_text='更新时间',
        auto_now=True,
    )

    def __str__(self):
        return "{}:uid:{}".format(self.id, self.user_id if self.user else '-')

    class Meta:
        verbose_name = '用户jwt登录日志'
        verbose_name_plural = verbose_name
        permissions = ALL_PERMS
